package com.kitty.game.player.serializer;

import com.kitty.game.role.model.Role;
import com.kitty.game.skill.model.SkillBox;
import com.kitty.game.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;

public class SkillBoxSerializer implements IPlayerPropSerializer {

    @Override
    public void serialize(Role player) {
        if (player.getSkillBox() != null) {
            player.setSkillBoxJson(JsonUtils.object2String(player.getSkillBox()));
        }
    }

    @Override
    public void deserialize(Role player) {
        String json = player.getSkillBoxJson();
        if (StringUtils.isNotEmpty(json)) {
            player.setSkillBox(JsonUtils.string2Object(json, SkillBox.class));
        }
    }
}
